<?php
include('../include/util.inc.php');
session_start();
$PDO = getPDO();

$category = $PDO->quote($_GET['category']);
$level = intval($_GET['level']);
$size = intval( $_SESSION['quiz_size']);
$score = intval($_GET['score']);
$timelimit = intval($_GET['timelimit']);

if (isset($_SESSION['uid'])) {
    $uid = intval($_SESSION['uid']);
    // $uid = 1;
    $quiz_start_time = $_SESSION['quiz_start_time'];
    // $quiz_start_time = time();
    $hid = $PDO->quote(str_pad($uid, 4, '0', STR_PAD_LEFT) . date("YmdHis", $quiz_start_time));
    $hdate = $PDO->quote(date("Y-m-d H:i:s", $quiz_start_time));


    $sql = "INSERT INTO history (`hdate`, `uid`, `hid`, `hcategory`, `hlevel`, `hsize`, `hscore`, `htimelimit`)
VALUES ($hdate, $uid, $hid, $category, $level, $size, $score, $timelimit)";
    // echo $sql;l
    try{
        $PDO->query($sql);
        echo 'successful';
    }catch (PDOException $e) {
        echo $e->getMessage();
    }
    
}else{
    echo 'customer';
}

unset($_SESSION['quiz_size']);
unset($_SESSION['quiz_start_time']);


?>